package com.mybatis.basic.fileupload;

import org.springframework.web.multipart.MultipartFile;

public class FileUploadBase {
	//文件名称
	private String fileName;
	//文件大小
	private Long fileSize;
	//文件类型
	private String fileType;
	//文件后缀
	private String suffix;
	//文件上传路径
	private String filePath;
	//允许上传的文件类型
	private String[] allowFileType = {};
	//允许上传的文件大小(单位MB)
	private Long allowSize = 2L;

	/**
	 * 创建文件名（当前时间戳+3位随机数）
	 * @return
	 */
	public String createFileName(){
		StringBuilder s = new StringBuilder();
		s.append(System.currentTimeMillis())
		 .append((int)(Math.random()*900)+100);
		return s.toString();
	}

	public void checkFile(MultipartFile file) {
		
	}

	/**
	 * GET AND SET
	 * @return
	 */
	public String getFileName() { return fileName; }
	public void setFileName(String fileName) {this.fileName = fileName;}

	public long getFileSize() {return fileSize;}
	public void setFileSize(long fileSize) {this.fileSize = fileSize;}

	public String getFileType() {return fileType;}
	public void setFileType(String fileType) {this.fileType = fileType;}

	public String getSuffix() {return suffix;}
	public void setSuffix(String suffix) {this.suffix = suffix;}

	public String getFilePath() {return filePath;}
	public void setFilePath(String filePath) {this.filePath = filePath;}

	public String[] getAllowFileType() {return allowFileType;}
	public void setAllowFileType(String[] allowFileType) {this.allowFileType = allowFileType;}

	public Integer getAllowSizeByMB() {return allowSize.intValue();}
	/*兆转换为字节单位*/
	public long getAllowSize() {return allowSize*1024*1024;}
	/*字节单位转换为兆*/
	public void setAllowSize(long allowSize) {this.allowSize = allowSize/1024/1024;}
}
